package org.nmgyjt.springboot.utils;


import org.apache.commons.lang.StringUtils;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IKSUtil {

    public static List<String> getStringList(String text) throws Exception {
        //独立Lucene实现
        StringReader re = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(re, true);
        Lexeme lex;
        List<String> s = new ArrayList<>();
        while ((lex = ik.next()) != null) {
            s.add(lex.getLexemeText());
        }
        return s;
    }


    public static Boolean checkStringListInSpiltArray(String splitStr, String strings) throws Exception {
        String[] split = splitStr.split("、");
        List<String> list = Arrays.asList(split);
        Boolean flag = false;
        if (StringUtils.isNotEmpty(strings)) {
            for (String str : list) {
                if (strings.contains(str)) {
                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }

}
